import React, { Component } from 'react';
import {connect} from "react-redux"
import * as actions from "./reducers/actions"
import {bindActionCreators} from "redux"

class App extends Component {

  constructor(props){
    super();
    console.log(props)
    this.numberadd = this.numberadd.bind(this)
  }
  numberadd = () =>{
    let number = Number(this.refs.numberinput.value);
    this.props.actions.jianumber(number)
  }
  render() {
    return (
      <div className="App">
        <h3>我是app</h3>
        <h3>{this.props.v}</h3>
        <input type="number" placeholder="请输入你想要加减的数字" ref="numberinput"></input><br />
        <button onClick={this.numberadd}>加输入的数字</button><br />
        <button onClick={this.props.actions.zengjia}>+1</button>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <button onClick={this.props.actions.jianshao}>-1</button>
      </div>
    );
  }
}
// let App = ({state, actions}) =>{
//   return(
//     <div>
//       <h3>我是app</h3>
//       <p>{state}</p>
//       <input type="button" value="减一" onClick={actions.jianshao}></input>
//       {" "}
//       <input type="button" value="加一" onClick={actions.zengjia}></input>
//     </div>
//   )
// }

export default connect(
  (state) =>{
    return state
  },
  (dispatch)=>{
    return{
      actions:bindActionCreators(actions,dispatch)
    }
  }
)(App);
